package com.li.controller;



import com.li.pojo.Course2;
import com.li.service.Course2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Collection;

@Controller
public class Course2Controller {
    @Resource
    Course2Service service;

    @RequestMapping("/course2")
    public String list(Model model){
        Collection<Course2> course2s=service.allCourse2();
        model.addAttribute("course2s",course2s);
        return "course2/list";
    }
    @GetMapping(value = "/tocourse2")
    public String tocourse2(Model model){

        return "course2/add";
    }
    @RequestMapping(value = "/course2/add")
    //@ResponseBody
    public String addCourse2(Course2 course2){
        if(service.addCourse2(course2))return "redirect:/course2";
        return "课程号重复，添加失败";
    }
    @RequestMapping(value = "/course2/query")
    public String queryCourse2(){
        return "";
    }

    @GetMapping("/course2/{cnumber}")
    public String toupdateCourse2(
            @PathVariable("cnumber")String cnumber, Model model){
        Course2 course2=new Course2(cnumber);

        course2=service.queryCourse2(course2);
        model.addAttribute("cou",course2);
        //Collection<Class> classes=studentService.allClass();
        // model.addAttribute("classes",classes);
        return "course2/update";
    }
    @RequestMapping(value = "/course2/update")
    public String updateCourse2(Course2 course2){
        System.out.println("1");
        service.updateCourse2(course2);
        return "redirect:/course2";
    }
    @RequestMapping(value = "/deletecourse2/{cnumber}")
    public String deleteCourse2(@PathVariable("cnumber")String cnumber){
        Course2 course2=new Course2(cnumber);
        service.deleteCourse2(course2);
        return "redirect:/course2";
    }
}